package com.example.zjhuojback.controller;


import com.example.zjhuojback.common.Result;
import com.example.zjhuojback.entity.Submission;
import com.example.zjhuojback.service.SubmissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/submission")
public class SubmissionController {

    @Autowired
    private SubmissionService submissionService;


    // 获取所有提交记录（分页）
    @GetMapping("/getAll/{userId}")
    public Result getAllSubmissions(
            @PathVariable int userId,
            @RequestParam int pageNum,
            @RequestParam int pageSize,
            @RequestParam(required = false) Integer problemId,
            @RequestParam(required = false) String username,
            @RequestParam(required = false) String language,
            @RequestParam(required = false) String result) {

        // 创建 Submission 对象
        Submission submission = new Submission();
        submission.setProblemId(problemId);
        submission.setUsername(username);
        submission.setLanguage(language);
        submission.setResult(result);
        // 获取分页后的提交记录
        List<Submission> submissions = submissionService.getPaginatedSubmissions(pageNum, pageSize, submission, userId);

        // 获取记录总数
        int total = submissionService.getSubmissionCount();

        return Result.success(submissions, total);
    }
}